﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Job.Entity;
using Job.Logic.Personal;

namespace Job.Web.userControls.Personal
{
    public partial class AccountModify : System.Web.UI.UserControl
    {
        private int JobAccountId 
        {
            get
            {
                MySession session = new MySession();
                SessionPersonal person = session.GetPersonalFromSession();
                return person.PersonAccountid;
            }
        }

        private void ShowMessage(string message)
        {
            this.msgTd.Visible = true;
            this.msgTd.InnerHtml = "<font color='#990000'>" + message + "</font>";
            this.msgTd.Height = "30px";
            this.msgTd.VAlign = "middle";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try 
            {
                JobPersonAccount account = new PersonalLogic().GetAccountByAccountid(JobAccountId);

                tbName.Text = account.UserName;
                rblSex.SelectedValue = account.UserSex.ToString();
                tbCardId.Text = account.UserCard;
                tbEmail.Text = account.LinkEmail;
                tbPhone.Text = account.LinkPhone;
   
            }
            catch(Exception ex)
            {
                ShowMessage("系统内部异常，查询账户失败！");
                return ;
            }

            this.msgTd.Visible = false;            
        }

        protected void btSave_Click(object sender, EventArgs e)
        {
            try
            {
                JobPersonAccount account = new JobPersonAccount();
                account.PersonAccountId = JobAccountId;
                account.UserName = tbName.Text.Trim();
                account.UserSex = Convert.ToInt32(rblSex.SelectedValue);
                account.UserCard = tbCardId.Text.Trim();
                account.LinkPhone = tbPhone.Text.Trim();
                account.LinkEmail = tbEmail.Text.Trim();

                new PersonalLogic().UpdateAccount(account);
                ShowMessage("保存账户信息成功！");
            }
            catch (Exception ex)
            {
                ShowMessage("系统异常，保存账户信息失败！");
            }
        }
    }
}